﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace QL_tour
{
    class Ketnoicsdl
    {
        public static SqlConnection con = null;
        public static string connect = @"Data Source=MILION-PC\SQLEXPRESS;Initial Catalog=QL_Tour;Integrated Security=True";
        public  static void mo_ketnoi(){
            try
            {
                con =new SqlConnection(connect);
                con.Open();
                //MessageBox.Show("kết nối thành công!");
            }
            catch {
                MessageBox.Show("kết nối thất bại!");
            }
        }
        public static void dong_ketnoi() {
            try
            {
                con = new SqlConnection(connect);
                con.Close();
            }
            catch { }
        }
        public static DataTable datatb(string sql) {
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sda.Fill(dt);
            return dt;
        }
        public static void datatb1(string sql) {
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.CommandText = sql;
            cmd.ExecuteNonQuery();
        }

        public static DataTable laybang(string tenbang) {
            string sql = "select * from " +tenbang;
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            SqlCommandBuilder cmb = new SqlCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds, tenbang);
            return ds.Tables[0];
        }
    }
}
